package com.hd.crdao.activity;

import android.widget.TextView;

import com.google.gson.Gson;
import com.hd.crdao.R;
import com.hd.crdao.base.BaseSecondActivity;
import com.hd.crdao.bean.RepaymentDetailBean;
import com.hd.crdao.config.Constants;
import com.hd.crdao.utils.MyToast;
import com.hd.crdao.utils.StringUtils;
import com.hd.crdao.view.ExpandHeadView;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import butterknife.BindView;
import okhttp3.Call;

/**
 * @author Programming
 * @date 2017/10/18 0018
 */

public class RepaymentDetailActivity extends BaseSecondActivity {
    @BindView(R.id.repaymentDetail_head)
    ExpandHeadView mRepaymentDetailHead;
    @BindView(R.id.interestMoney)
    TextView mInterestMoney;
    @BindView(R.id.veBrand)
    TextView mVeBrand;
    @BindView(R.id.vcCredit)
    TextView mVcCredit;
    @BindView(R.id.vcRate)
    TextView mVcRate;
    @BindView(R.id.term)
    TextView mTerm;
    @BindView(R.id.fkDate)
    TextView mFkDate;
    @BindView(R.id.interestDays)
    TextView mInterestDays;
    @BindView(R.id.repaymentAmount)
    TextView mRepaymentAmount;
    @BindView(R.id.repaymentAccount)
    TextView mRepaymentAccount;
    @BindView(R.id.repaymentNumber)
    TextView mRepaymentNumber;
    @BindView(R.id.openAccountBank)
    TextView mOpenAccountBank;
    @BindView(R.id.endDate)
    TextView mEndDate;


    @Override
    protected int setContentView() {

        return R.layout.activity_repaymentdetail;
    }

    @Override
    protected ExpandHeadView setExpandHeadView() {
        return mRepaymentDetailHead;
    }

    @Override
    protected void initView() {
        initData();

    }

    private void initData() {
        String vehCreditId = getIntent().getStringExtra("vehCreditId")+"";
        OkHttpUtils.post().url(Constants.GETREPAYMENTINFO_URL)
                .addParams("sign", Constants.SIGN)
                .addParams("vehCreditId", vehCreditId)
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                MyToast.show("网络开了个差");
            }

            @Override
            public void onResponse(String response, int id) {
                RepaymentDetailBean repaymentDetailBean = new Gson().fromJson(response, RepaymentDetailBean.class);
                if (repaymentDetailBean.getSuccess() == 0) {
                    MyToast.show(repaymentDetailBean.getMessage());
                    mEndDate.setText(repaymentDetailBean.getVehCredit().getEndDate());
                    mInterestMoney.setText(StringUtils.doubleToString(repaymentDetailBean.getVehCredit().getVehicleTbl().getInterestMoney()));
                    mVeBrand.setText(repaymentDetailBean.getVehCredit().getVehicleTbl().getVeBrand());
                    mVcCredit.setText(StringUtils.doubleToString(repaymentDetailBean.getVehCredit().getVcCredit()));
                    mVcRate.setText(repaymentDetailBean.getVehCredit().getVcRate() + "%");
                    mTerm.setText(repaymentDetailBean.getVehCredit().getTerm());
                    mFkDate.setText(repaymentDetailBean.getVehCredit().getFkDate());
                    mInterestDays.setText(repaymentDetailBean.getVehCredit().getVehicleTbl().getInterestDays());
                    mRepaymentAmount.setText(String.valueOf(repaymentDetailBean.getVehCredit().getVehicleTbl().getRepaymentAmount()));

                    if (repaymentDetailBean.getVehCredit().getVcRate() == 0.99) {
                        mRepaymentAccount.setText("上海珑亿融资租赁有限公司");
                        mRepaymentNumber.setText("0338 4300 0400 1288 5");
                        mOpenAccountBank.setText("农行上海长风支行");
                    } else {
                        mRepaymentAccount.setText("严道先");
                        mRepaymentNumber.setText ("6222 0814 0200 5565 480");
                        mOpenAccountBank.setText ("工行福州五四北路支行");
                    }
                } else {
                    MyToast.show(repaymentDetailBean.getMessage());
                }
            }
        });

    }


}
